﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class MP_PositionCommandDtls : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private IPositionCommandDtlsBLL CmdPosDtls = new PositionCommandDtlsBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            lblCmdPosSeq.Text = Request.QueryString["CmdPosSeq"].ToString();

            if (!Page.IsPostBack)
            {
                LoadDataGrid(lblCmdPosSeq.Text.Length > 0 ? Int32.Parse(lblCmdPosSeq.Text) : (int?)null);
            }
        }
        public void LoadDataGrid(Nullable<int> CmdPosSeq)
        {
            DataSet ds = CmdPosDtls.LoadPositionCommandDtls((int?)null, CmdPosSeq);
            DataTable dt = null;

            if (ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                RadGrid1.DataSource = dt;
                RadGrid1.DataBind();
            }
        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            PositionCommandDtlsInfo Info = new PositionCommandDtlsInfo();

            if (e.CommandName == "DeleteAll")
            {
                GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem);
                if (items.Length > 0)
                {
                    ((GridCommandItem)items[0]).FireCommandEvent("DeleteSelected", "");
                }
                else
                {
                    RadGrid1.Items[0].FireCommandEvent("DeleteSelected", "");
                }
            }
            else if (e.CommandName == "Delete")
            {
                string Seq = (e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["cmd_pos_dtls_seq"].ToString();

                Info.Seq = Seq.Length > 0 ? Int32.Parse(Seq) : (int?)null;
                Info.UpdatedBy = ssMng.EmpSeqI;

                CmdPosDtls.Delete(Info);
            }

            LoadDataGrid(lblCmdPosSeq.Text.Length > 0 ? Int32.Parse(lblCmdPosSeq.Text) : (int?)null);
        }
    }
}
